﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Profile;
using System.Data;
using System.IO;
using System.Web.UI.HtmlControls;

namespace WebSite.admin.link
{
    public partial class addlink : BaseAdmin
    {
        protected Button Button1;
        protected CheckBox CheckBox1;

        protected HtmlInputFile file1;
        protected HtmlForm form1;
        protected ImageButton ImageButton1;
        protected Label Label1;
        protected TextBox linkfile;
        protected TextBox linkurl;
        protected HtmlTableRow smallfile;
        protected TextBox txtCn;
        protected TextBox txtOrder;





        // Methods
        protected void Button1_Click(object sender, EventArgs e)
        {
            upload upload = new upload();
            string str = upload.Up(this.file1, "../../uploadfile/link/");
            base.Response.Write(upload.Resup[Convert.ToInt32(str)]);
            this.linkfile.Text = upload.s;
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            if (base.Request.QueryString["lid"] != null)
            {
                SQLAccess.DoSql(string.Concat(new object[] { "update DB_Link set linkname='", re.replace(this.txtCn.Text), "',linkorder=", re.replace(this.txtOrder.Text), ",linkfile='", re.replace(this.linkfile.Text), "',linkurl='", re.replace(this.linkurl.Text), "',visible=", this.CheckBox1.Checked ? "1" : "0", ",updatetime='", DateTime.Now, "' where linkid=", base.Request.QueryString["lid"], "" }));
                base.Response.Write("<script language='javascript'>alert('友情链接信息修改成功');window.location.href='link.aspx';</script>");
                base.Response.End();
            }
            else
            {
                SQLAccess.DoSql(string.Concat(new object[] { "insert into DB_Link (linkname,linkorder,visible,linkfile,updatetime,linkurl,languages) values ('", re.replace(this.txtCn.Text), "',", re.replace(this.txtOrder.Text), ",", this.CheckBox1.Checked ? "1" : "0", ",'", re.replace(this.linkfile.Text), "','", DateTime.Now, "','", re.replace(this.linkurl.Text), "',", info.languages(""), ")" }));
                base.Response.Write("<script language='javascript'>alert('友情链接信息添加成功');window.location.href='link.aspx';</script>");
                base.Response.End();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
          
            if (!base.IsPostBack && (base.Request.QueryString["lid"] != null))
            {
                this.upbind();
                this.Label1.Text = "修改友情链接";
            }
        }

        private void upbind()
        {
            string sql = "select top 1 * from DB_Link where linkid=" + base.Request.QueryString["lid"];
            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            this.txtCn.Text = table.Rows[0]["linkname"].ToString();
            this.txtOrder.Text = table.Rows[0]["linkorder"].ToString();
            this.linkfile.Text = table.Rows[0]["linkfile"].ToString();
            this.linkurl.Text = table.Rows[0]["linkurl"].ToString();
            this.CheckBox1.Checked = (bool)table.Rows[0]["visible"];
        }

   

    }
}